<?php

	class GetListingCommand implements ICommand
	{
		public function execute($event)
		{
			return $this->select_Hierarchy(ROOT);
		}

		function select_Hierarchy($path)
		{
			$path = rtrim(str_replace("\\", "/", $path), '/') . '/';
			$dir = dir($path);
			$buffer = array();
												
			while (false !== ($entry = $dir->read())) 
			{
				if ($entry != "." && $entry != "..")
				{
					$item = array();
					$item["n"] = $entry;
					$item["s"] = filesize($path.$entry);
										
					if (is_dir($path.$entry))
					{
						$item["children"] = array();
						$listSub = $this->select_Hierarchy($path.$entry);
						
						foreach ($listSub AS $sub)
						{
							$item["children"] []= $sub;
						}
						
						$item["t"] = "d";
					}
					else
					{
						$item["t"] = "f";
					}
					
					$buffer []= $item;
				}
			}
			
			$dir->close();
			
			return $buffer;
		}		
	}